import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service - 语言维护
 * @date: 2018-8-10

 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { parseParameters, filterNullValueObject, getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var tenantId = getCurrentOrganizationId(); // 处理Api

function languageApi() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/languages") : 'languages';
}
/**
 *查询页面数据
 * @async
 * @function queryLanguage
 * @param {?string} params.searchCode - 语言编码
 * @param {Number} [params.page = 0] - 数据页码
 * @param {Number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */


export function queryLanguage(_x) {
  return _queryLanguage.apply(this, arguments);
}
/**
 *编辑行数据
 * @async
 * @function editLanguage
 * @param {!number} params.id - 语言Id
 * @param {!number} params.objectVersionNumber 语言版本好号
 * @param {!string} params.code - 语言编码
 * @param {!string} params.name - 语言名称
 * @param {!string} param.description - 语言描述
 * @returns {object} fetch Promise
 */

function _queryLanguage() {
  _queryLanguage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = filterNullValueObject(parseParameters(params));
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(languageApi()), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryLanguage.apply(this, arguments);
}

export function editLanguage(_x2) {
  return _editLanguage.apply(this, arguments);
}

function _editLanguage() {
  _editLanguage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(languageApi(), "/").concat(params.id), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _editLanguage.apply(this, arguments);
}